Update the TPM hotplug scripts to determine the reason of a
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Sat, 4 Feb 2006 09:58:28 +0000 (10:58 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Sat, 4 Feb 2006 09:58:28 +0000 (10:58 +0100)
device creation (create/resume).

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
tools/examples/vtpm
tools/examples/vtpm-common.sh

index bc8b64d9740fedf8daedb551b0ea0b60f752f5fd..2d590a0158dd9458d77f5fd68ecbf2e965f66a13 100644 (file)
@@ -4,19 +4,19 @@ dir=$(dirname "$0")
 . "$dir/vtpm-common.sh"
 
 
-case "$command" in
-    online | offline)
-        exit 0
-        ;;
-esac
-
 case "$command" in
   add)
     vtpm_create_instance
   ;;
+  online)
+    vtpm_create_instance
+  ;;
   remove)
     vtpm_remove_instance
   ;;
+  offline)
+    vtpm_remove_instance
+  ;;
 esac
 
 log debug "Successful vTPM operation '$command'."
index 4c90558ef83edac2699848860563cb4394cc5e00..8344fdcfef5ce976e69e760015924ec5e698882e 100644 (file)
@@ -219,6 +219,17 @@ function remove_entry () {
 }
 
 
+# Find the reason for the creation of this device:
+# Set global REASON variable to 'resume' or 'create'
+function get_create_reason () {
+       local resume=$(xenstore-read $XENBUS_PATH/resume)
+       if [ "$resume" == "True" ]; then
+               REASON="resume"
+       else
+               REASON="create"
+       fi
+}
+
 #Create a vTPM instance
 # If no entry in the TPM database is found, the instance is
 # created and an entry added to the database.
@@ -226,6 +237,7 @@ function vtpm_create_instance () {
        local domname=$(xenstore_read "$XENBUS_PATH"/domain)
        local res
        set +e
+       get_create_reason
        find_instance $domname
        res=$?
        if [ $res -eq 0 ]; then
@@ -243,7 +255,7 @@ function vtpm_create_instance () {
                add_instance $domname $instance
                if [ "$REASON" == "create" ]; then
                        vtpm_create $instance
-               elif [ "$REASON" == "hibernate" ]; then
+               elif [ "$REASON" == "resume" ]; then
                        vtpm_resume $instance $domname
                else
                        #default case for 'now'
@@ -252,11 +264,12 @@ function vtpm_create_instance () {
        fi
        if [ "$REASON" == "create" ]; then
                vtpm_reset $instance
-       elif [ "$REASON" == "hibernate" ]; then
+       elif [ "$REASON" == "resume" ]; then
                vtpm_setup $instance
        else
                #default case for 'now'
-               vtpm_reset $instance
+               #vtpm_reset $instance
+               true
        fi
        xenstore_write $XENBUS_PATH/instance $instance
        set -e
@@ -273,7 +286,7 @@ function vtpm_remove_instance () {
                #Something is really wrong with the DB
                log err "vTPM DB file $VTPMDB has no entry for '$domname'"
        else
-               if [ "$REASON" == "hibernate" ]; then
+               if [ "$REASON" == "suspend" ]; then
                        vtpm_suspend $instance
                fi
        fi